package cm.tl.pms.sys.util;

import cn.hutool.core.util.ReUtil;

public class PasswordStrengthValidator {

    // 定义密码强度正则表达式
//    private static final String PASSWORD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~`])(?=.*[\u4e00-\u9fa5]).{8,}$";
//    private static final String PASSWORD_REGEX = "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[^\\da-zA-Z\\s]).{1,9}$";
    private static final String PASSWORD_REGEX = "^(?![0-9A-Za-z]+$)(?![0-9A-Z\\W]+$)(?![0-9a-z\\W]+$)(?![A-Za-z\\W]+$)[0-9A-Za-z~!@#$%^&*()_+`\\-={}|\\[\\]\\\\:\";'<>?,./]{8,}$";

    public static boolean isValidPassword(String password) {
        // 使用正则表达式验证密码强度
        return ReUtil.isMatch(PASSWORD_REGEX, password);
    }

    public static void main(String[] args) {
        String password1 = "Password1.";
        String password2 = "weakpass";
        String password3 = "Password1？";
        String password4 = "Password1。";

        System.out.println("密码1是否有效: " + isValidPassword(password1)); // 输出: true
        System.out.println("密码2是否有效: " + isValidPassword(password2)); // 输出: false
        System.out.println("密码3是否有效: " + isValidPassword(password3)); // 输出: true
        System.out.println("密码4是否有效: " + isValidPassword(password4)); // 输出: true
    }
}